home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / PNL Libraries / MyEnterPassword.p < prev    next >
Text File  |  1995-03-17  |  3KB  |  149 lines

  1. unit MyEnterPassword;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Events, Dialogs;
  7.  
  8.     procedure CreateEnterPassword (var p: ptr; dlg: DialogPtr; item: integer);
  9.     procedure DisposeEnterPassword (var p: ptr);
  10.     procedure HandleEnterPassword (p: ptr; var er: EventRecord);
  11.     procedure GetEnterPassword (p: ptr; var password: str255);
  12.     procedure SetEnterPassword (var p: ptr; password: str255);
  13.     procedure PasteEnterPassword (p: ptr; h: handle);
  14.  
  15. implementation
  16.  
  17.     uses
  18.         MyStrings, MyTypes, MyUtils, MyDialogs, QLowLevel;
  19.  
  20.     const
  21.         my_bullet = '•';
  22.  
  23.     type
  24.         EPRecord = record
  25.                 teh: TEHandle;
  26.                 dlg: DialogPtr;
  27.                 item: integer;
  28.             end;
  29.         EPRecordPtr = ^EPRecord;
  30.  
  31.     procedure CreateEnterPassword (var p: ptr; dlg: DialogPtr; item: integer);
  32.         var
  33.             dest, view: Rect;
  34.             ep: EPRecordPtr;
  35.     begin
  36.         SetPort(dlg);
  37.         p := NewPtr(SizeOf(EPRecord));
  38.         ep := EPRecordPtr(p);
  39.         SetRect(dest, 8000, 8010, 8100, 8020);
  40.         view := dest;
  41.         ep^.teh := TENew(dest, view);
  42.         ep^.dlg := dlg;
  43.         ep^.item := item;
  44. {    h := TEGetText(ep^.teh);}
  45.     end;
  46.  
  47.     procedure DisposeEnterPassword (var p: ptr);
  48.         var
  49.             ep: EPRecordPtr;
  50.     begin
  51.         ep := EPRecordPtr(p);
  52.         TEDispose(ep^.teh);
  53.         DisposePtr(ptr(ep));
  54.         p := nil;
  55.     end;
  56.  
  57.     procedure SetEnterPassword (var p: ptr; password: str255);
  58.         var
  59.             ep: EPRecordPtr;
  60.             i: integer;
  61.     begin
  62.         ep := EPRecordPtr(p);
  63.         TESetText(@password[1], length(password), ep^.teh);
  64.         for i := 1 to length(password) do begin
  65.             password[i] := my_bullet;
  66.         end;
  67.         SetItemText(ep^.dlg, ep^.item, password);
  68.     end;
  69.  
  70.     procedure GetEnterPassword (p: ptr; var password: str255);
  71.         var
  72.             ep: EPRecordPtr;
  73.             h: CharsHandle;
  74.     begin
  75.         ep := EPRecordPtr(p);
  76.         h := TEGetText(ep^.teh);
  77.         HandleToString(h, password);
  78.     end;
  79.  
  80.     procedure HandleEnterPassword (p: ptr; var er: EventRecord);
  81.         var
  82.             ep: EPRecordPtr;
  83.             ch: Char;
  84.     begin
  85.         ep := EPRecordPtr(p);
  86.         if (ep^.dlg = FrontWindow) & (SelectedTextItem(ep^.dlg) = ep^.item) then begin
  87.             if (er.what in [keyDown, AutoKey]) & (BAND(er.modifiers, cmdKey) = 0) then begin
  88.                 ch := chr(BAND(er.message, charCodeMask));
  89.                 case ch of
  90.                     cr, enter, tab, leftArrow, rightArrow, upArrow, downArrow: 
  91.                         ;
  92.                     otherwise begin
  93.                         if (ch <> bs) & (ch < spc) then begin
  94.                             SysBeep(1);
  95.                             er.what := nullEvent;
  96.                         end
  97.                         else begin
  98.                             TESetSelect(dialogPeek(ep^.dlg)^.textH^^.selStart, dialogPeek(ep^.dlg)^.textH^^.selEnd, ep^.teh);
  99.                             TEKey(ch, ep^.teh);
  100.                             if (ch <> bs) & DirtyKey(ch) then begin
  101.                                 er.message := ord(my_bullet);
  102.                             end;
  103.                         end;
  104.                     end;
  105.                 end;
  106.             end;
  107.         end;
  108.     end;
  109.  
  110.     procedure PasteEnterPassword (p: ptr; h: handle);
  111.         var
  112.             ep: EPRecordPtr;
  113.             len: longInt;
  114.             i: integer;
  115.             s: str255;
  116.             bad: boolean;
  117.             th: TEHandle;
  118.     begin
  119.         ep := EPRecordPtr(p);
  120.         if (SelectedTextItem(ep^.dlg) = ep^.item) then begin
  121.             len := GetHandleSize(h);
  122.             bad := len > 255;
  123.             if not bad then begin
  124.                 for i := 0 to len - 1 do begin
  125.                     if BAND(AddPtrLong(h^, i)^, $FF) < 32 then begin
  126.                         bad := true;
  127.                         leave;
  128.                     end;
  129.                 end;
  130.             end;
  131.             if bad then begin
  132.                 SysBeep(1);
  133.             end
  134.             else begin
  135.                 th := dialogPeek(ep^.dlg)^.textH;
  136.                 HLock(h);
  137.                 TESetSelect(th^^.selStart, th^^.selEnd, ep^.teh);
  138.                 TEDelete(ep^.teh);
  139.                 TEInsert(h^, len, ep^.teh);
  140.                 s[0] := chr(len);
  141.                 for i := 1 to len do begin
  142.                     s[i] := my_bullet;
  143.                 end;
  144.                 TEDelete(th);
  145.                 TEInsert(@s[1], len, th);
  146.             end;
  147.         end;
  148.     end;
  149. end.